package cn.diandiandidi.demo;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
		
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);        
        Log.d(this.toString(), "onCreate called:" );
        
        
        Button btnFinish = (Button)findViewById(R.id.btnFinish);
        btnFinish.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
				Log.w(this.toString(), "finish called:" );
			}
		});
        
        Button btnStartFullScrActiviy = (Button)findViewById(R.id.btnFullScr);
        btnStartFullScrActiviy.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(MainActivity.this, FullScrActivity.class);
				startActivity(intent);
			}
		});
        
        Button btnDialog = (Button)findViewById(R.id.btnDialog);
        btnDialog.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(MainActivity.this, DialogActivity.class);
				startActivity(intent);				
			}
		});
        
        Button btnAlert = (Button)findViewById(R.id.btnAlert);
        btnAlert.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				new AlertDialog.Builder(MainActivity.this).setIcon(R.drawable.icon).setTitle(
						"AlertDialog").setMessage("Nothing")
						.setNeutralButton("OK",
								new DialogInterface.OnClickListener() {
									@Override
									public void onClick(DialogInterface dialog, int which) {
									}
								}).create().show();
			}
		});
        
        Button btnInnerDialog = (Button)findViewById(R.id.btnInnerDialog);
        btnInnerDialog.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				InnerDialog d = new InnerDialog(MainActivity.this);
				d.show();
			}
		});        
        
        Button btnResult = (Button)findViewById(R.id.btnResult);
        btnResult.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(MainActivity.this, ResultActivity.class);
				startActivityForResult(intent, 0);
			}
		});
    }

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		Log.d(this.toString(), "onDestroy called:");
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		Log.d(this.toString(), "onPause called:");
	}

	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
		super.onRestart();
		Log.d(this.toString(), "onRestart called:");
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		Log.d(this.toString(), "onResume called:");
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		Log.d(this.toString(), "onStart called:");
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		Log.d(this.toString(), "onStop called:");		
	}
    
	class InnerDialog extends Dialog {
		public InnerDialog(Context context) {
			super(context);
			setContentView(R.layout.dialog_activity_layout);
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {		
		System.out.println("Result:" + resultCode);
		//if(resultCode == 200) finish();		//v3
		super.onActivityResult(requestCode, resultCode, data);
	}	
		
}
